import numpy as np
# 1.导入 pyplot 模块
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
# 2.绘制点
# 房屋面积
house_area = np.array([225.98, 247.07, 253.14, 457.85, 241.58,
                       301.01, 20.67, 288.64, 163.56, 120.06, 207.83, 342.75, 147.9, 53.06,
                       224.72, 29.51, 21.61, 483.21, 245.25, 399.25, 343.35])
# 房屋价格
house_price = np.array([196.63, 203.88, 210.75, 372.74, 202.41, 247.61,
                        24.9, 239.34, 140.32, 104.15, 176.84, 288.23, 128.79, 49.64, 191.74,
                        33.1, 30.74, 400.02, 205.35, 330.64, 283.45])
plt.scatter(house_area, house_price, s=50, c='y', edgecolors='k')
# 3.完善图表
plt.title('房屋面积和房屋价格的关系')
plt.xlabel('房屋面积(平方米)')
plt.ylabel('房屋价格(万元)')
plt.grid(visible=True, linewidth=0.5) # 添加网格
plt.xlim(house_area.min()-30,house_area.max()+30) # 设置 x 轴的刻度范围
# 4.展示图表
plt.show()